home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Enigma Amiga CD / Listati / 67-Settembre-DIDATTICA-LIST.TX < prev    next >
Text File  |  1992-09-02  |  8KB  |  166 lines

  1. /****************************************************************************
  2. * Listato 1                                                                 *
  3. * Questo programma apre una finestra con menù di esempio; il colore delle   *
  4. * opzioni dipende dagli IntuiText; quello di sfondo e di primo piano del    *
  5. * blocco e della barra dipendono dal FrontPen e BackPen nella definizione   *
  6. * della finestra; vi sono anche sotto-menù con mutua-esclusione.            *
  7. ****************************************************************************/
  8.  
  9. #define INTUI_V36_NAMES_ONLY
  10.  
  11. /* inclusione file di supporto */
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/screens.h>
  16. #include <graphics/gfx.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/graphics_protos.h>
  20. #include <clib/layers_protos.h>
  21. #include <clib/dos_protos.h>
  22.  
  23. struct Library *IntuitionBase = NULL;     /* puntatore a intuition.library */
  24. struct Screen *pubscreen = NULL;          /* puntatore al workbench */
  25. struct Window *finestra = NULL;           /* puntatore alla finestra */
  26. struct MsgPort *UPort;                    /* puntatore alla porta IDCMP */
  27.  
  28. /* strutture definite per i menù */
  29. struct IntuiText ItemText00 = {0,1,JAM2,0,1,NULL,"Nuovo",NULL};
  30. struct IntuiText ItemText01 = {0,1,JAM2,0,1,NULL,"Apri...",NULL};
  31. struct IntuiText ItemText02 = {0,1,JAM2,0,1,NULL,"Salva",NULL};
  32. struct IntuiText ItemText03 = {0,1,JAM2,0,1,NULL,"Salva come...",NULL};
  33. struct IntuiText ItemText04 = {0,1,JAM2,0,1,NULL,"Esci",NULL};
  34. struct IntuiText ItemText10 = {0,1,JAM2,0,1,NULL,"Cut",NULL};
  35. struct IntuiText ItemText11 = {0,1,JAM2,0,1,NULL,"Copy",NULL};
  36. struct IntuiText ItemText12 = {0,1,JAM2,0,1,NULL,"Paste",NULL};
  37. struct IntuiText ItemText13 = {0,1,JAM2,0,1,NULL,"Clear",NULL};
  38. struct IntuiText ItemText20 = {0,1,JAM2,0,1,NULL,"Tipo",NULL};
  39. struct IntuiText ItemText21 = {0,1,JAM2,0,1,NULL,"Caratteristiche",NULL};
  40. struct IntuiText ItemText30 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Topaz",NULL};
  41. struct IntuiText ItemText31 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Times",NULL};
  42. struct IntuiText ItemText32 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Triumvirate",NULL};
  43. struct IntuiText ItemText33 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Elvetica",NULL};
  44. struct IntuiText ItemText34 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Diamond",NULL};
  45. struct IntuiText ItemText40 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Plain",NULL};
  46. struct IntuiText ItemText41 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Bold",NULL};
  47. struct IntuiText ItemText42 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Italic",NULL};
  48. struct IntuiText ItemText43 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Underline",NULL};
  49. struct IntuiText ItemText44 = {0,1,JAM2,CHECKWIDTH,1,NULL,"Outline",NULL};
  50.  
  51. #define MENUITEMFLAGS ITEMTEXT|ITEMENABLED|HIGHCOMP
  52.  
  53. struct MenuItem Item44 = {NULL,120,42,130,10,MENUITEMFLAGS|CHECKIT,0x0001,(APTR)&ItemText44,NULL,0,NULL,MENUNULL};
  54. struct MenuItem Item43 = {&Item44,120,32,130,10,MENUITEMFLAGS|CHECKIT,0x0001,(APTR)&ItemText43,NULL,0,NULL,MENUNULL};
  55. struct MenuItem Item42 = {&Item43,120,22,130,10,MENUITEMFLAGS|CHECKIT,0x0001,(APTR)&ItemText42,NULL,0,NULL,MENUNULL};
  56. struct MenuItem Item41 = {&Item42,120,12,130,10,MENUITEMFLAGS|CHECKIT,0x0001,(APTR)&ItemText41,NULL,0,NULL,MENUNULL};
  57. struct MenuItem Item40 = {&Item41,120,2,130,10,MENUITEMFLAGS|CHECKIT|CHECKED,0xFFFE,(APTR)&ItemText40,NULL,0,NULL,MENUNULL};
  58. struct MenuItem Item34 = {NULL,120,42,130,10,MENUITEMFLAGS|CHECKIT,0xFFEF,(APTR)&ItemText34,NULL,0,NULL,MENUNULL};
  59. struct MenuItem Item33 = {&Item34,120,32,130,10,MENUITEMFLAGS|CHECKIT,0xFFF7,(APTR)&ItemText33,NULL,0,NULL,MENUNULL};
  60. struct MenuItem Item32 = {&Item33,120,22,130,10,MENUITEMFLAGS|CHECKIT,0xFFFB,(APTR)&ItemText32,NULL,0,NULL,MENUNULL};
  61. struct MenuItem Item31 = {&Item32,120,12,130,10,MENUITEMFLAGS|CHECKIT,0xFFFD,(APTR)&ItemText31,NULL,0,NULL,MENUNULL};
  62. struct MenuItem Item30 = {&Item31,120,2,130,10,MENUITEMFLAGS|CHECKIT|CHECKED,0xFFFE,(APTR)&ItemText30,NULL,'P',NULL,MENUNULL};
  63. struct MenuItem Item21 = {NULL,0,10,130,10,MENUITEMFLAGS,0,(APTR)&ItemText21,NULL,0,&Item40,MENUNULL};
  64. struct MenuItem Item20 = {&Item21,0,0,130,10,MENUITEMFLAGS,0,(APTR)&ItemText20,NULL,0,&Item30,MENUNULL};
  65. struct MenuItem Item13 = {NULL,0,30,130,10,MENUITEMFLAGS,0,(APTR)&ItemText13,NULL,0,NULL,MENUNULL};
  66. struct MenuItem Item12 = {&Item13,0,20,130,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText12,NULL,'P',NULL,MENUNULL};
  67. struct MenuItem Item11 = {&Item12,0,10,130,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText11,NULL,'C',NULL,MENUNULL};
  68. struct MenuItem Item10 = {&Item11,0,0,130,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText10,NULL,'X',NULL,MENUNULL};
  69. struct MenuItem Item04 = {NULL,0,40,200,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText04,NULL,'E',NULL,MENUNULL};
  70. struct MenuItem Item03 = {&Item04,0,30,200,10,MENUITEMFLAGS,0,(APTR)&ItemText03,NULL,0,NULL,MENUNULL};
  71. struct MenuItem Item02 = {&Item03,0,20,200,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText02,NULL,'S',NULL,MENUNULL};
  72. struct MenuItem Item01 = {&Item02,0,10,200,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText01,NULL,'A',NULL,MENUNULL};
  73. struct MenuItem Item00 = {&Item01,0,0,200,10,(MENUITEMFLAGS|COMMSEQ),0,(APTR)&ItemText00,NULL,'N',NULL,MENUNULL};
  74.  
  75. struct Menu sMenu2 = {NULL,172,0,58,8,MENUENABLED,"Fonts.",&Item20};
  76. struct Menu sMenu1 = {&sMenu2,110,0,50,8,MENUENABLED,"Edit.",&Item10};
  77. struct Menu sMenu0 = {&sMenu1,0,0,98,8,MENUENABLED,"Principale.",&Item00};
  78.  
  79. /* definizione prototipi di funzione */
  80. void WaitEvent(struct MsgPort *,struct IntuiMessage *);
  81. void CloseAll(void);
  82. void OpenAll(void);
  83.  
  84. /* funzione per l'attesa di messaggi da Intuition */
  85. void WaitEvent(struct MsgPort *porta,struct IntuiMessage *mess)
  86. {
  87.   struct IntuiMessage *msg;
  88.  
  89.   while ((msg = (struct IntuiMessage *)GetMsg(porta)) == NULL)
  90.     WaitPort(porta);
  91.  
  92.   CopyMem(msg,mess,sizeof(struct IntuiMessage));
  93.   return;
  94. }
  95.  
  96. /* procedura CloseAll() */
  97. void CloseAll()
  98. {
  99.   if (finestra != NULL) CloseWindow(finestra);
  100.   if (pubscreen != NULL) UnlockPubScreen(NULL,pubscreen);
  101.   if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  102.  
  103.   exit(0);
  104. }
  105.  
  106. /* procedura OpenAll() */
  107. void OpenAll()
  108. {
  109.   /* apriamo intuition.library, almeno version 36 */
  110.   if ((IntuitionBase = OpenLibrary("intuition.library",36L)) == NULL)
  111.     CloseAll();
  112.  
  113.   /* blocca lo schermo pubblico di default */
  114.   if ((pubscreen = LockPubScreen(NULL)) == NULL)
  115.     CloseAll();
  116.  
  117.   /* apre finestra spostabile, con il gadget di chiusura */
  118.   if ((finestra = OpenWindowTags(NULL,WA_Left,10,
  119.                                       WA_Top,10,
  120.                                       WA_Width,350,
  121.                                       WA_Height,150,
  122.                                       WA_Title,"Esempio menù",
  123.                                       WA_DragBar,TRUE,
  124.                                       WA_CloseGadget,TRUE,
  125.                                       WA_DepthGadget,TRUE,
  126.                                       WA_Flags,WFLG_NOCAREREFRESH,
  127.                                       WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_MENUPICK,
  128.                                       WA_PubScreen,pubscreen,
  129.                                       TAG_END)) == NULL)
  130.     CloseAll();
  131.   UPort = finestra -> UserPort;
  132.  
  133.   return;
  134. }
  135.  
  136. void main()
  137. {
  138.   struct IntuiMessage mm;
  139.   UWORD MenuNum,Menu,MenuItem,MenuSubItem;
  140.   struct MenuItem *item;
  141.  
  142.   OpenAll();  /* apre tutte le strutture dati */
  143.   SetMenuStrip(finestra,&sMenu0);
  144.  
  145.   while(1)
  146.   {
  147.     WaitEvent(UPort,&mm);  /* attende un evento */
  148.     if (mm.Class == IDCMP_CLOSEWINDOW) break; /* se gadget di chiusura esci */
  149.     else if (mm.Class == IDCMP_MENUPICK) /* selezione menù */
  150.     {
  151.       MenuNum = mm.Code;
  152.       while (MenuNum != MENUNULL)
  153.       {
  154.         item = ItemAddress(&sMenu0,MenuNum);
  155.         Menu = MENUNUM(MenuNum);
  156.         MenuItem = ITEMNUM(MenuNum);
  157.         MenuSubItem = SUBNUM(MenuNum);
  158.         printf("Selezionato menù: %d, opzione %d, sotto-opzione %d\n",Menu,MenuItem,MenuSubItem);
  159.         MenuNum = item -> NextSelect;
  160.       }
  161.     }
  162.   }
  163.   ClearMenuStrip(finestra);
  164.   CloseAll();  /* chiudi tutto ed esci */
  165. }
  166.